package Presenter;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import Models.Brinks;

public class BrinksPresenter extends AbstractPresenter<Brinks> {
	final String SINGLEITEM = "brinks";
	final String MULTIITEM = "brinkss";
	
	public ArrayList<Brinks> tryJSONParseArray(String input){
		return super.doJSONParseArray(input, SINGLEITEM, MULTIITEM);
	}
	
	public Brinks tryJSONParse(String input){
		return super.doJSONParse(input, SINGLEITEM);
	}
	
	public Brinks createItemFromJSONObject(JSONObject jsonObject){
		Brinks item = new Brinks();
		try{
			item.setBrinkDescription(jsonObject.getString("brinkDescription"));
			item.setBrinkID(jsonObject.getInt("brinkID"));
			item.setBrinkNotes(jsonObject.getString("brinkNotes"));
			item.setBrinkVolume(jsonObject.getDouble("brinkVolume"));
			item.setBrinkWeight(jsonObject.getDouble("brinkWeight"));
			return item;
		} catch(JSONException ex){
			ex.printStackTrace();
		} catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public JSONObject createJSON(Brinks item){
		try{
			JSONObject json = new JSONObject();
			json.put("brinkDescription", item.getBrinkDescription());
			json.put("brinkID", item.getBrinkID());
			json.put("brinkNotes", item.getBrinkNotes());
			json.put("brinkVolume", item.getBrinkVolume());
			json.put("brinkWeight", item.getBrinkWeight());
			return json;
		} catch(JSONException ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public Brinks getEmptyEntity(){
		Brinks entity = new Brinks();
		return entity;
	}
}
